﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;

using AwinDotNet;


namespace Controls
{
    /// <summary>
    /// Summary description for SiteCategoryList
    /// </summary>
    public class BreadCrumbs : System.Web.UI.Control
    {
        private int _CurrentCatID = 0;

        public BreadCrumbs()
        {

            if (HttpContext.Current.Request.QueryString["cat"] != null)
            {
                int.TryParse(HttpContext.Current.Request.QueryString["cat"], out _CurrentCatID);
            }
            else
            {
                _CurrentCatID = 0;
            }


        }

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer);


            //List<AwinDotNet.ProductCategory> path = AwinDotNet.AwinAPI.GetCategoryPath(_CurrentCatID).ToList<AwinDotNet.ProductCategory>();

            List<AwinDotNet.ProductCategory> path = AwinDotNet.AwinAPI.ProductCategories.GetCategoryPath(_CurrentCatID);

            StringBuilder sb = new StringBuilder();


            foreach (AwinDotNet.ProductCategory c in path)
            {
                string url = @"<a href=""listproducts.aspx?cat={0}"">{1}</a>";

                url = string.Format(url, c.ID, c.Name);

                sb.Append(" > " + url);
            }

            writer.Write(sb.ToString());

        }


    }
}